package com.example.demo.controller;

import com.example.demo.entity.Food;
import com.example.demo.enums.ResultEnum;
import com.example.demo.service.FoodService;
import com.example.demo.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/food")
public class FoodController {
    @Autowired
    private FoodService foodService;

    @RequestMapping("/findFood")
    public ResultVO findFood(){
        List<Food> lists = foodService.findFood();
        return new ResultVO(ResultEnum.SUCCESS,lists);
    }

    @RequestMapping("/findToLike")
    public ResultVO findToLike(String fname){
        List<Food> lists = foodService.findToLike(fname);
        return new ResultVO(ResultEnum.SUCCESS,lists);
    }
    @RequestMapping("/addFood")
    public ResultVO addFood(@RequestParam Map<String,String> map){
        int result = foodService.addFood(map);
        return new ResultVO(ResultEnum.SUCCESS,result);
    }
    @RequestMapping("/updateFood")
    public ResultVO updateFood(@RequestParam Map<String,String> map){
        int result = foodService.updateFood(map);
        return new ResultVO(ResultEnum.SUCCESS,result);
    }
    @RequestMapping("/delFood")
    public ResultVO delFood(String fid){
        int result = foodService.delFood(Integer.valueOf(fid));
        return new ResultVO(ResultEnum.SUCCESS,result);
    }
}
